package com.jiangman.weather.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.jiangman.weather.R;
import com.jiangman.weather.base.BaseFragment;
import com.jiangman.weather.bean.CommonResponse;
import com.jiangman.weather.callback.CustomCallback;
import com.jiangman.weather.callback.RsponseStateListenerImp;
import com.jiangman.weather.constant.ConstantUrl;
import com.jiangman.weather.view.EditTextWithDel;
import com.zhy.http.okhttp.OkHttpUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import util.ToastUitl;

/**
 * Created by secoro on 2017/4/27.
 */

public class RegistFragment extends BaseFragment {
    @BindView(R.id.userphone)
    EditTextWithDel userphone;
    @BindView(R.id.userpassword)
    EditTextWithDel userpassword;
    @BindView(R.id.regist)
    Button regist;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_regist, null);
        ButterKnife.bind(this, inflate);
        return inflate;

    }

    @OnClick(R.id.regist)
    public void onClick() {
        OkHttpUtils.post()
                .url(ConstantUrl.baseUrl+"Weather/regist")
                .addParams("user_name",userphone.getText().toString())
                .addParams("user_pwd",userpassword.getText().toString())
                .build()
                .execute(new CustomCallback(new RsponseStateListenerImp<CommonResponse>() {

                    @Override
                    public void fail(CommonResponse response) {
                        ToastUitl.show(response.msg, Toast.LENGTH_SHORT);
                    }

                    @Override
                    public void success(CommonResponse response, boolean isRefresh) {
                        ToastUitl.show(response.msg, Toast.LENGTH_SHORT);
                    }

                    @Override
                    public void error(Exception e) {
                        System.out.println(e.toString());
                    }
                }, CommonResponse.class, false));
    }
}
